package com.zjpavt.client.networkdevice;

import com.zjpavt.client.udp.UdpSender;
import lombok.extern.slf4j.Slf4j;

/**
 * 在线模式下的suite
 * pc端控台状态
 * @author zyc
 */
@Slf4j
public class SunLightDeviceOnline {
    public static final String DESTINATION_IP = "show.zjpavt.com";
    public static final int DESTINATION_PORT = 4003;
    public static int sceneIdNow = -1;
    public static void main(String[] args) {
        sendSuiteScene(2);
    }
    /**
     * 发送suite场景。
     * 从文件中获取suite设备的IP地址 如果获取不到则使用默认的IP=192.168.1.220
     * 可以编辑suite_device_ip,指定UDP地址 第四位地址可以设置到255发UDP广播。
     * action=discover 可以广播寻找当前局域网内的suite控台设备
     * @param sceneId
     * @return
     */
    public static boolean sendSuiteScene(int sceneId) {
        if (sceneId == sceneIdNow) {
            return false;
        }
        long startTime = System.currentTimeMillis();
        String readyCommand = "action=ready";
        byte[] UdpBytes = readyCommand.getBytes();
        UdpSender.sendUdpPacket(DESTINATION_IP, DESTINATION_PORT, UdpBytes);
        try {
            Thread.sleep(5);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        String readyCommand1 = "action=update_element&id=" + sceneId + "&page=0&value=1&type=btn&event=down";
        byte[] UdpBytes1 = readyCommand1.getBytes();
        UdpSender.sendUdpPacket(DESTINATION_IP, DESTINATION_PORT, UdpBytes1);
        log.info("DESTINATION_IP = " + DESTINATION_IP + " SCENE_ID= " + sceneId+ " msg=" + readyCommand1 + " use time=" +(System.currentTimeMillis() -startTime));
        return true;
    }
}
